import {Component, OnInit, ViewChild} from '@angular/core';
import {BsModalRef, BsModalService} from 'ngx-bootstrap';

export let Zero3Confirm: Zero3ConfirmComponent;

@Component({
    selector: 'app-zero3-confirm',
    templateUrl: './zero3-confirm.component.html',
    styleUrls: ['./zero3-confirm.component.css']
})
export class Zero3ConfirmComponent implements OnInit {

    @ViewChild('template')
    template;

    message: string;

    modalRef: BsModalRef;

    reqResolve;

    reqReject;

    constructor(private modalService: BsModalService) {
        Zero3Confirm = this;
    }

    req(message: string): Promise<boolean> {
        this.message = message;
        this.modalRef = this.modalService.show(this.template, {class: 'modal-sm'});
        return new Promise((resolve, reject) => {
            this.reqResolve = resolve;
            this.reqReject = reject;
        });
    }

    confirm(): void {
        this.modalRef.hide();
        this.reqResolve(true);
    }

    decline(): void {
        this.modalRef.hide();
        this.reqResolve(false);
    }

    ngOnInit(): void {
    }

}
